package com.dgut.admodule.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dgut.admodule.entity.Bidding;
import com.dgut.admodule.entity.dto.BiddingQueryDTO;
import com.dgut.admodule.service.IBiddingService;
import com.dgut.common.util.ExtAjaxResponse;
import com.dgut.common.util.ExtPageable;

@Controller
@RequestMapping("/bidding")
public class BiddingController {
	@Autowired
	private IBiddingService biddingService;
	
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(Bidding bidding) {
		try {
			biddingService.saveOrUpdate(bidding);
			return new ExtAjaxResponse(true,"保存成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"保存失败！");
		}
	}
	
	@RequestMapping("/delete")
	public @ResponseBody ExtAjaxResponse delete(@RequestParam Long id) 
	{
		try {
			Bidding bidding =  biddingService.findOne(id);
			if(null!=bidding) {
				biddingService.delete(bidding);
			}
			return new ExtAjaxResponse(true,"删除成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"删除失败！");
		}
	}
	
	@RequestMapping("/deleteBiddings")
	public @ResponseBody ExtAjaxResponse deleteStaffs(@RequestParam Long[] ids) 
	{
		try {
			List<Long> idLists = Arrays.asList(ids);
			if(null!=idLists) {
				biddingService.delete(idLists);
			}
			return new ExtAjaxResponse(true,"删除成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"删除失败！");
		}
	}
	
	@RequestMapping("/findOne")
	public @ResponseBody Bidding findOne(@RequestParam Long id) 
	{
		Bidding bidding =  biddingService.findOne(id);
		
		return bidding;
	}
	
	@RequestMapping("/findNew")
	public @ResponseBody Bidding findNew() 
	{
		return biddingService.findNew();
	}
	
	@RequestMapping("/findAll")
	public @ResponseBody List<Bidding> findAll() 
	{
		List<Bidding> lists =  biddingService.findAll();
		
		return lists;
	}
	
	@RequestMapping("/findPage")
	public @ResponseBody Page<Bidding> findPage(BiddingQueryDTO biddingQueryDTO,ExtPageable pageable) 
	{
		pageable.setSort("bidId");
		Page<Bidding> page =  biddingService.findAll(BiddingQueryDTO.getSpecification(biddingQueryDTO), pageable.getPageable());
		
		return page;
	}
}
